﻿// ===================================================================
// 项目说明
//====================================================================
// SunCity@Copy Right 2006-2008
// 文件： DataAccessFactory.cs
// 项目名称：SunCity_MS
// 创建时间：2015/3/18
// 负责人：Chris
// ===================================================================
using System;
using System.Reflection;
using EMS20.IDataAccessLayer;

namespace EMS20.DALFactory
{
    /// <summary>
    /// 数据层工厂
    /// </summary>
    public class DataAccessFactory
    {
		private static readonly string path = System.Configuration.ConfigurationManager.AppSettings["ProjectManageDal"]; 
		
		private static object CreateObject(string path,string CacheKey)
		{			
			object objType = DataCache.GetCache(CacheKey);
			if (objType == null)
			{
				try
				{
					objType = Assembly.Load(path).CreateInstance(CacheKey);					
					DataCache.SetCache(CacheKey, objType);
				}
				catch{}

			}
			return objType;
		}
		/// <summary>
    	/// 通过反射机制，实例化Category接口对象。
    	/// </summary>
		///<returns>Category接口对象</returns>
		public static ICategoryDataAccessLayer Create_Category()
		{		
			string CacheKey = path+".CategoryDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (ICategoryDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化Contents接口对象。
    	/// </summary>
		///<returns>Contents接口对象</returns>
		public static IContentsDataAccessLayer Create_Contents()
		{		
			string CacheKey = path+".ContentsDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (IContentsDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化feedback接口对象。
    	/// </summary>
		///<returns>feedback接口对象</returns>
		public static IfeedbackDataAccessLayer Create_feedback()
		{		
			string CacheKey = path+".feedbackDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (IfeedbackDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化Menus接口对象。
    	/// </summary>
		///<returns>Menus接口对象</returns>
		public static IMenusDataAccessLayer Create_Menus()
		{		
			string CacheKey = path+".MenusDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (IMenusDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化News接口对象。
    	/// </summary>
		///<returns>News接口对象</returns>
		public static INewsDataAccessLayer Create_News()
		{		
			string CacheKey = path+".NewsDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (INewsDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化Product接口对象。
    	/// </summary>
		///<returns>Product接口对象</returns>
		public static IProductDataAccessLayer Create_Product()
		{		
			string CacheKey = path+".ProductDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (IProductDataAccessLayer)objType;		
		}

		/// <summary>
    	/// 通过反射机制，实例化UserInfo接口对象。
    	/// </summary>
		///<returns>UserInfo接口对象</returns>
		public static IUserInfoDataAccessLayer Create_UserInfo()
		{		
			string CacheKey = path+".UserInfoDataAccessLayer";	
			object objType=CreateObject(path,CacheKey);			
			return (IUserInfoDataAccessLayer)objType;		
		}

		
    }
}

